<?php
class Workflow_Service_Sendmail implements Workflow_ServiceObject
{
	protected $to;
	protected $from;
	protected $subject;
	protected $cc;
	protected $bcc;
	protected $body;
	
	public function __construct($to, $from, $subject, $cc, $bcc, $body)
	{
		$this->to = $to;
		$this->from = $from;
		$this->cc = $cc;
		$this->bcc = $bcc;
		$this->body = $body;
	}
	
	public function execute( Workflow_Execution $execution )
	{		
		$parameters = $execution->getVariables();
		
		if (!class_exists('Smarty', true)) {
            require_once 'Smarty/Smarty.class.php';
        }
        
        $smarty = new \Smarty();
        $smarty->caching = 0;
        
        $smarty->left_delimiter = "{";
        $smarty->right_delimiter = "}";
        $smarty->assign($parameters);
        
        $body = $smarty->fetch('string:'.$this->body);	
		
		$mail = new Zend_Mail();
		$mail->addTo($this->to)
			->setFrom($this->from)
			->addCc($this->cc)
			->addBcc($this->bcc)
			->setBodyHtml($body, 'utf-8');
			
		$mail->send();	
	}
}
?>